package com.ruoyi.web.controller.business;

import com.ruoyi.business.domain.entity.TbStore;
import com.ruoyi.business.iService.ITbStoreService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.page.TableSupport;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.validate.AddGroup;
import com.ruoyi.common.validate.EditGroup;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 店铺Controller
 * 
 * @author ruoyi
 * @date 2025-07-26
 */
@Validated
@RestController
@RequestMapping("/business/store")
public class TbStoreController extends BaseController {
    @Autowired
    private ITbStoreService tbStoreService;

    /**
     * 查询店铺列表
     */
    @PreAuthorize("@ss.hasPermi('business:store:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbStore tbStore) {
        // startPage();
        return tbStoreService.selectTbStorePage(tbStore, TableSupport.getPageDomain());
    }

    /**
     * 导出店铺列表
     */
    @PreAuthorize("@ss.hasPermi('business:store:export')")
    @Log(title = "店铺", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbStore tbStore) {
        List<TbStore> list = tbStoreService.selectTbStoreList(tbStore);
        ExcelUtil<TbStore> util = new ExcelUtil<TbStore>(TbStore.class);
        util.exportExcel(response, list, "店铺数据");
    }

    /**
     * 获取店铺详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:store:query')")
    @GetMapping(value = "/{storeId}")
    public AjaxResult getInfo(@PathVariable("storeId") Long storeId) {
        return success(tbStoreService.getById(storeId));
    }

    /**
     * 新增店铺
     */
    @Anonymous
//    @PreAuthorize("@ss.hasPermi('business:store:add')")
//    @Log(title = "店铺", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated(AddGroup.class) @RequestBody TbStore tbStore) {
        return toAjax(tbStoreService.save(tbStore));
    }

    /**
     * 修改店铺
     */
    @PreAuthorize("@ss.hasPermi('business:store:edit')")
    @Log(title = "店铺", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated(EditGroup.class) @RequestBody TbStore tbStore) {
        return toAjax(tbStoreService.updateById(tbStore));
    }

    /**
     * 删除店铺
     */
    @PreAuthorize("@ss.hasPermi('business:store:remove')")
    @Log(title = "店铺", businessType = BusinessType.DELETE)
	@DeleteMapping("/{storeIds}")
    public AjaxResult remove(@PathVariable Long[] storeIds) {
        return toAjax(tbStoreService.removeByIds(Arrays.asList(storeIds)));
    }
}
